/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 000.c
 * draw a circle gragh with "*", test: draw a circle and a parabola
 ***********************************************************************************************/

#include <stdio.h>
#include <math.h>

/*
 * we can see difference between these two drawing method from this example. in the first one,
 * the maximum value repeats twice because the algorithm assume the symmetry. but in the second
 * one, we just draw a point when it comes without any assumption.
 */

int main()
{
	int x = 0, y = 0, m = 0, n = 0;
        // circle
	for (y = 10; y >= -10; y--)
	{
		m = 2*sqrt(100-y*y);
		for (x = 1; x < 30-m; x++) printf(" "); // (30, 0) is the center of circle
		printf("*");
		for(; x < 30+m; x++) printf(" ");
		printf("*\n");
	}
        // circle and parabola
	double z = 0.0;
        for (z = 1.0; z >= -1.0; z -= 0.1)
        {
                m = 2*sqrt(1-z*z)*10;
		if (z >= 0.0) n = 2*sqrt(z)*10;
		for (x = 0; x <=50; x++)
		{
			if (x == 30-m || x == 30+m) printf("*");
			else if (z >= 0.0 && (x == 30-n || x == 30+n)) printf("+");
			else printf(" ");
		}
		printf("\n");
	}
}

